/*************************************************************************
 Copyright (C) Unpublished Unis Software, Inc. All rights reserved.
 Unis Software, Inc., Confidential and Proprietary.

 This software is subject to copyright protection
 under the laws of the Public of China and other countries.

 Unless otherwise explicitly stated, this software is provided
 by Unis "AS IS".
 *************************************************************************/
package com.unis.service.eweboffice;

import java.util.ArrayList;
import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;

import com.unis.common.util.TemplateUtil;
import com.unis.dao.IDataSet4iBatis;
import com.unis.model.BaseModel;
import com.unis.model.eweboffice.DocumentProc;

/**
 * @author CSJ (email:Cao.shengjie777@gmail.com)
 * @since 2013-04-09
 */
@Service("documentprocService")
public class DocumentProcServiceImpl implements DocumentProcService {

    private IDataSet4iBatis iDataSet4iBatis;

    /****************************************
     * Insert a instace of DocumentProc
     ****************************************/
    public void insert(DocumentProc documentproc) throws Exception {
        documentproc.setClbh(TemplateUtil.genUUID());
        iDataSet4iBatis.insert(documentproc);
    }

    /****************************************
     * Update a instace of DocumentProc
     ****************************************/
    public void update(DocumentProc documentproc) throws Exception {
        iDataSet4iBatis.update(documentproc);
    }

    /****************************************
     * Delete a instace of DocumentProc
     ****************************************/
    public void delete(DocumentProc documentproc) throws Exception {
        iDataSet4iBatis.delete(documentproc);
    }

    /****************************************
     * Insert instaces of SysUser
     ****************************************/
    public void batchInsert(DocumentProc documentproc) throws Exception {
        throw new RuntimeException("Not yet implement!");
    }

    /****************************************
     * Delete instaces of SysUser
     ****************************************/
    public void batchDelete(DocumentProc documentproc) throws Exception {
        String statementId = documentproc.getStatmentId();
        String mainId = documentproc.getId();
        String[] ids = mainId.split(",");
        List<BaseModel> documentprocList = new ArrayList<BaseModel>();
        for (String id : ids) {
            DocumentProc model = new DocumentProc();
            model.setStatmentId(statementId);
            model.setId(id.trim());
            documentprocList.add(model);
        }
        iDataSet4iBatis.batchDelete(documentprocList);
    }

    /****************************************
     * Query instaces of DocumentProc
     ****************************************/
    public List<BaseModel> queryAsList(DocumentProc documentproc) throws Exception {
        String queryListStatement = "";
        if (documentproc.isPaging()) {
            queryListStatement = documentproc.getStatmentId();
            documentproc.setStatmentId("DocumentProc.queryRecordsCount");
            BaseModel baseModel = iDataSet4iBatis.queryAsObject(documentproc);
            documentproc.setTotalCount(baseModel.getTotalCount());
            documentproc.setStatmentId(queryListStatement);
        }
        return iDataSet4iBatis.queryAsList(documentproc);
    }

    /****************************************
     * Query a instaces of DocumentProc
     ****************************************/
    public BaseModel queryAsObject(DocumentProc documentproc) throws Exception {
        return iDataSet4iBatis.queryAsObject(documentproc);
    }

    @Resource
    public void setiDataSet4iBatis(IDataSet4iBatis iDataSet4iBatis) {
        this.iDataSet4iBatis = iDataSet4iBatis;
    }
}
